package com.yn.module.material.web;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicParameters;
import com.yn.common.utils.constant.Const;
import com.yn.common.utils.web.R;
import com.yn.module.material.service.HospJointGroupService;
import com.yn.module.material.utils.enums.ConstEnum;
import com.yn.module.material.utils.xls.ExcelDTO;
import com.yn.module.material.utils.xls.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * HospJointGroupController操作类
 *
 * @author 叶甯
 * @version 1.0.0
 * @date 2022-10-13 16:09:37
 */
@RestController
@Api(tags = "医保组套数据校验")
@ApiSupport(order = 1001)
@RequiredArgsConstructor
@RequestMapping("/hosp/jointGroup")
public class HospJointGroupController {
    @Resource
    private HospJointGroupService baseService;

    @ApiOperation(httpMethod = Const.Method.POST, value = "query:标准字典：导入")
    @ApiOperationSupport(order = 1)
    @PostMapping("/import")
    public R excelImport(ExcelDTO excelInfo, @RequestParam("file") MultipartFile file) throws Exception {
        Map<String, Object> selfParams = new HashMap<>();
        baseService.importExcelData(selfParams, excelInfo, file);
        return R.success().message("导入成功");
    }

    @ApiOperation(httpMethod = Const.Method.GET, value = "query:模板下载")
    @ApiOperationSupport(order = 2)
    @GetMapping(value = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void downloadTpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        ExcelUtils.doExportZipTemplate(req, resp, ExcelUtils.IMPORT_TPL_PATH, ConstEnum.ExcelEnum.MEDICARE_GROUP.getName());
    }

}
